﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Cloak.NUnit;
using Cloak.Reflection;
using Moq;
using NUnit.Framework;
using Ruleweaver.Rules;

namespace Ruleweaver.Conditions.Schemas
{
	public class GetDeclaredConditionsFromCompositeSource : Behavior
	{
		private Condition _condition0;
		private Condition _condition1;
		private Condition _condition2;
		private CompositeConditionSource _compositeSource;
		private IList<Condition> _compositeSourceConditions;

		protected override void Given()
		{
			var method0 = Reflect.Func<ICheckable<int>, Check<int>>(Checkable.IsPositive);
			var method1 = Reflect.Func<ICheckable<int>, Check<int>>(Checkable.IsEven);
			var method2 = Reflect.Func<ICheckable<string>, Check<string>>(Checkable.IsEmpty);

			_condition0 = new Condition(Rule.Check(method0), new ConditionKey(typeof(int)));
			_condition1 = new Condition(Rule.Check(method1), new ConditionKey(typeof(int)));
			_condition2 = new Condition(Rule.Check(method2), new ConditionKey(typeof(string)));

			var source0Mock = new Mock<IConditionSource>();
			var source1Mock = new Mock<IConditionSource>();

			source0Mock.Setup(source => source.GetConditions()).Returns(new[] { _condition0, _condition1 });
			source1Mock.Setup(source => source.GetConditions()).Returns(new[] { _condition2 });

			_compositeSource = new CompositeConditionSource(source0Mock.Object, source1Mock.Object);
		}

		protected override void When()
		{
			_compositeSourceConditions = _compositeSource.GetConditions().ToList();
		}

		[Then]
		public void ConditionsAreMerged()
		{
			Assert.IsTrue(_compositeSourceConditions.Contains(_condition0));
			Assert.IsTrue(_compositeSourceConditions.Contains(_condition1));
			Assert.IsTrue(_compositeSourceConditions.Contains(_condition2));
		}
	}
}